<template name="homePage">
	<view class="m-page">
		<scroll-view scroll-y class="scrollPage">
			<view class="UCenter-bg">
				<image src="http://yun.hiai.top/wave.gif" mode="scaleToFill" class="gif-wave"></image>
				<view class="meiDate">
					<view class="mei-content">{{r_content}}</view>
					<view class="mei-content">{{r_note}}</view>
					<view style="float:right;margin-right: 10px;">{{r_dateline}}</view>
				</view>
			</view>
		</scroll-view>
		<view class="cu-bar search bg-white" scroll-x="true">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" v-model="s_name" placeholder="查询就是这么简单..." confirm-type="search"></input>
			</view>
		</view>
		<view class="m-card-list">
			<view v-for="item in wordList" :key="item.id" :class="['m-card', item.isTop===1? 'm-top' : '']">
				<view class="m-date"><text class="cuIcon-titles text-orange "></text>{{item.addtime.slice(0,10)}}</view>
				<view class="m-title">{{item.title}}</view>
				<view class="m-content">
					{{item.content}}
				</view>
			</view>
		</view>
		<baseTabar></baseTabar>
	</view>
</template>

<script>
	export default {
		name: "homePage",
		data() {
			return {
				r_content: "",
				r_dateline: "",
				r_note: "",
				searchValue: "",
				word_title: "",
				word_content: "",
				word_date: "",
				word_top: false,
				page: 1,
				s_name: "",
				wordList: ""
			}
		},
		methods: {},
		onLoad() {
			uni.request({
				url: 'http://open.iciba.com/dsapi/', //仅为示例，并非真实接口地址。
				success: (res) => {
					// console.log(res);
					this.r_content = res.data.content;
					this.r_dateline = res.data.dateline;
					this.r_note = res.data.note;
				}
			});
			uni.login({
				provider: 'weixin',
				success: function(res) {
					// console.log(res);
					uni.request({
						url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wx640e59a84b026efd&secret=a7096370acf8e956b6b8deef471855d7&js_code=' +
							res.code + '&grant_type=authorization_code',
						method: 'GET',
						success: (res) => {
							// console.log(res.data.openid);
							uni.request({
								url: `http://127.0.0.1:9001/api/user/auth`,
								// url: `http://47.94.164.187:9001/api/user/auth?openid=${res.data.openid}`,
								method: 'POST',
								data: {
									openid: res.data.openid
								},
								success: (res) => {
									// console.log(res);
									uni.setStorageSync('token', res.data.data.token)
								}
							})
						}
					})
				}
			});
			uni.request({
				// url:'http://47.94.164.187:9001/api/content/list/',
				url: 'http://127.0.0.1:9001/api/content/list?page=' + this.page + '&s_name=' + this.s_name,
				method: 'GET',
				header: {
					token: uni.getStorageSync('token')
				},
				success: (res) => {
					// console.log(res)
					this.wordList = res.data.data.records
				}
			});
		}
	}
</script>

<style lang="scss" scoped>
	.m-page {
		.UCenter-bg {
			background-image: url(http://yun.hiai.top/ke_home_index.jpg);
			background-size: cover;
			height: 380rpx;
			display: flex;
			justify-content: center;
			padding-top: 40rpx;
			overflow: hidden;
			position: relative;
			flex-direction: column;
			align-items: center;
			color: #fff;
			font-weight: 300;
			text-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
		}

		.UCenter-bg text {
			opacity: 0.8;
		}

		.UCenter-bg image {
			width: 200rpx;
			height: 200rpx;
		}

		.UCenter-bg .gif-wave {
			position: absolute;
			width: 100%;
			bottom: 0;
			left: 0;
			z-index: 99;
			mix-blend-mode: screen;
			height: 100rpx;
		}

		.meiDate {
			margin: 0 40rpx;
		}

		.mei-content {
			padding: 10rpx;
		}

		.m-card-list {
			padding: 30rpx;

			.m-card {
				margin-bottom: 30rpx;
				padding: 20rpx;
				background: #fff;
				border-radius: 15rpx;

				&:last-child {
					margin-bottom: 0;
				}

				&.m-top {
					position: relative;

					&::after {
						position: absolute;
						content: "";

						border: {
							top: 14rpx solid red;
							right: 10rpx solid red;
							bottom: 14rpx solid transparent;
							left: 10rpx solid red;
						}

						;
						right: 40rpx;
						top:0;
					}
				}

				.m-date {
					color: #bcbcbc;
				}

				.m-title {
					font-size: 16px;
					margin-top: 20rpx;
				}

				.m-content {
					margin-top: 20rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2; //行数
					-webkit-box-orient: vertical;
					color: #bcbcbc;
					word-break: break-all;
				}
			}
		}
	}
</style>
